package practise.alogrithm.hundredInterviewQuestions.secondTime;

import java.util.HashMap;

/**
 * Created by Richard on 7/26/2014.
 */
public class FirstAppearOnceChar {
    public char find(String str){
        HashMap<Character,Integer> hash = new HashMap<>();
        for(int index=0; index<str.length();index++){
            hash.put(str.charAt(index),hash.get(str.charAt(index))==null?1:hash.get(str.charAt(index))+1);
        }
        for(int index=0; index<str.length();index++){
            if(hash.get(str.charAt(index))==1){
                return str.charAt(index);
            }
        }
        return '-';
    }

    public static void main(String[] args){
        System.out.println(new FirstAppearOnceChar().find("abcdefacde"));
    }
}
